package controller;

import java.util.List;

import javax.swing.JOptionPane;

import view.Mode;
import accounts.*;
import model.*;
import model.environmentConfig.*;

public class ConnectionTester
{
	protected static AuthorizationManager am = new AuthorizationManager();
	protected static EnvironmentManager em = new EnvironmentManager();
	protected static ConnectionManager cm = null;
		
	public static Authorization authenticateLogin(String username, String password)
	{
		Authorization a = am.authenticate(username, password);
		em.setAuthorization(a);
		return a;
	}
	
	public static Authorization getAuthorization(){
		return em.getAuthorization();
	}
	
	public static Mode getMode(){
		return em.getMode();
	}
	
	public static void setSimulatorMode(){
		em.setMode(Mode.SIMULATOR);
	}
	
	public static void setDesignerMode(){
		em.setMode(Mode.DESIGNER);
	}
	
	public static void setSecurityMode(){
		em.setMode(Mode.SECURITY);
	}
	
	public static void saveEnvironment(String XMLFilename)
	{
		em.saveEnvironment(XMLFilename);
	}
	
	public static void deleteEnvironment(String XMLFilename)
	{
		em.deleteEnvironment(XMLFilename);
	}
	
	public static void loadEnvironment(String XMLFilename)
	{
		em.loadEnvironment(XMLFilename);
	}
	
	public static void newEnvironment(){
		em.newEnvironment();
	}
	
	public static void submitForApproval(String XMLFilename)
	{
		em.submitForAproval(XMLFilename);
	}
	
	public static void modifyEnvironment(String XMLFilename)
	{
		em.modifyEnvironment(XMLFilename);
	}
	
	public static void copyEnvironment(String XMLFilename, String NewFilename)
	{
		em.copyEnvironment(XMLFilename,NewFilename);
	}
	
	public static void generateEnvDoc(String XMLFilename, String Reportname)
	{
		em.generateEnvDoc(XMLFilename,Reportname);
	}
	
	public static void stopSimulation()
	{
		if(cm != null){
			cm.stop();
			cm = null;
		}
	}
	
	public static void runSimulation()
	{
		System.out.println(em.getEnvironmentConfiguration());
		if(em.getEnvironmentConfiguration() != null){
			cm = new ConnectionManager(em.getEnvironmentConfiguration());
			cm.start();
		}
		else{
			JOptionPane.showConfirmDialog(null, 
					"No Environment Configuration setup!",
					"Confirm", JOptionPane.OK_CANCEL_OPTION);
		}
	}
	
	public static EnvironmentConfiguration createEnvironment()
	{
		return em.createEnvironment();
	}
	
	public static EnvironmentConfiguration getEnvironmentConfig()
	{
		return em.getEnvironmentConfiguration();
	}
	
	public static void addNode(Node node){
		em.addNode(node);
	}
	
	public static String getConfigFileName(){
		return em.getEnvironmentConfiguration().getFileName();
	}
	
	public static List<String> getConfigList(){
	
		return XMLInterface.getConfigList();
	}
	
	public static List<String> getApprovedList(){
		
		return XMLInterface.getApprovedList();
	}
	
	public static List<String> getSubmittedList(){
		
		return XMLInterface.getSubmittedList();
	}
	
	public static List<String> getRejectedList(){
		
		return XMLInterface.getRejectedList();
	}
	
	public static void setSelected(Object object){
		em.getEnvironmentConfiguration().setSelectedObj(object);
	}
	
	
}
